﻿local function AT2_IsSecure()
	AT2_Print(debugstack(2, 1, 1),"debug","AT2_IsSecure")
	if (debugstack(2,1,1):find("Interface\\AddOns\\AutoTalker2\\")) then
		return true
	else
		return false
	end
end


local timedSendModule = {}
timedSendModule["name"] = "timedSendModule"
timedSendModule["title"] = "Időzített küldés modul"
timedSendModule["data"]={}
timedSendModule["OnLoad"]=function() 
	timedSendModule["data"]["minInterval"]=120
	timedSendModule["data"]["currInterval"]=-1
	timedSendModule["data"]["startTime"]=-1 -- will be set to time()
	timedSendModule["data"]["autoSelectorValues"]={}
	timedSendModule["data"]["autoSelectorValues"]["often"]={2,10,30} -- min, max, recheck interval (in minutes; recheck length = asSeconds(recheck interval))
	timedSendModule["data"]["autoSelectorValues"]["normal"]={4,20,60}
	timedSendModule["data"]["autoSelectorValues"]["rare"]={15,60,90}
	timedSendModule["data"]["currentAutoSelector"]=false
end
timedSendModule["RegisterForSend"]=true
timedSendModule["OnUpdateLowPriority"]=true
timedSendModule["OnUpdate"]=function() 
	if (AT2_SendActive and AT2_SendMode=="timedSendModule") then
		if timedSendModule["data"]["startTime"]+timedSendModule["data"]["currInterval"]<=timedSendModule["data"]["currInterval"] then
			AT2_API_SendToChannel()
			--timedSendModule["data"]["currInterval"]=editboxValue<timedSendModule["data"]["minInterval"] and timedSendModule["data"]["minInterval"]) or (editboxValue)
		end
	end
end

timedSendModule["SendMode"]={}
timedSendModule["SendMode"]["Start"]=function() 
	--NYI
end
timedSendModule["SendMode"]["Stop"]=function() 
	--NYI
end

AT2_InsertModule(timedSendModule) -- Need to reorder functions in other files


local perMessageSendModule = {}
perMessageSendModule["name"] = "perMessageSendModule"
perMessageSendModule["title"] = "Üzenetenkénti küldés modul"
perMessageSendModule["data"]={}
perMessageSendModule["OnLoad"]=function() 
	perMessageSendModule["data"]["minInterval"]=15
	perMessageSendModule["data"]["currInterval"]=-1
	perMessageSendModule["data"]["remain"]=-1
	perMessageSendModule["data"]["autoSelectorValues"]={}
	perMessageSendModule["data"]["autoSelectorValues"]["often"]={15,25,30} -- (msg)min, (msg)max, (mins)recheck interval
	perMessageSendModule["data"]["autoSelectorValues"]["normal"]={20,50,60}
	perMessageSendModule["data"]["autoSelectorValues"]["rare"]={40,100,90}
	perMessageSendModule["data"]["currentAutoSelector"]=false
end
perMessageSendModule["RegisterForSend"]=true
perMessageSendModule["Events"]={ ["CHAT_MSG_CHANNEL"]=AT2() } -- todo, put rest of channels here too
perMessageSendModule["OnEvent"]=function(self, event, ...) 
	local arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13=select(1,...)
	if (AT2_SendActive and AT2_SendMode=="perMessageSendModule" and arg9 == AT2_API_GetCurrentChannel()) then
		if perMessageSendModule["data"]["remain"]<=perMessageSendModule["data"]["currInterval"] then
			AT2_API_SendToChannel()
			--perMessageSendModule["data"]["currInterval"]=editboxValue<perMessageSendModule["data"]["minInterval"] and perMessageSendModule["data"]["minInterval"]) or (editboxValue)
		else
			perMessageSendModule["data"]["remain"]=perMessageSendModule["data"]["remain"]-1
		end
	end
end

perMessageSendModule["SendMode"]={}
perMessageSendModule["SendMode"]["Start"]=function() 
	--NYI
end
perMessageSendModule["SendMode"]["Stop"]=function() 
	--NYI
end

AT2_InsertModule(perMessageSendModule)




-- Rewritten functions for modules above --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -

